# -*- coding: utf-8 -*-
# @Time    : 2024/7/8 14:21
# @Author  : wangwei
# @File    : ddt_keyword.py
import traceback

from common.Excel import Reader, Writer
from common.webkeyword import WebKeyword

# def run_web():
#     # 读写示例代码
#     webkeyword=WebKeyword()
#     reader = Reader()
#     # 打开一个excel
#     reader.open_excel('\\lib\\cases\\电商项目用例.xlsx')
#     # 获取所有sheet
#     sheets = reader.get_sheets()
#     print(sheets)
#     for sheet in sheets:
#         # 设置读取的sheet页面
#         reader.set_sheet(sheet)
#         # 读取当前sheet的所有行
#         lines = reader.readline()
#         for line in lines:
#             if len(line[0])>0 or len(line[1])>0:
#                 continue
#             print("line的值："+str(line))
#             casename=line[2]
#             key_word=line[3]
#             params=line[4:]
#             params=params[:params.index("")]
#             print("params的值："+str(params))
#             func=getattr(webkeyword,key_word)
#             res=func(*params)


def run_web():
    reader = Reader()
    writer = Writer()
    writer.copy_open('\\lib\\cases\\电商项目用例.xlsx','\\lib\\cases\\result-电商项目用例.xlsx')
    #读写示例代码
    webkeyword=WebKeyword()
    # 打开一个excel
    reader.open_excel('\\lib\\cases\\电商项目用例.xlsx')
    # 获取所有sheet
    sheets = reader.get_sheets()
    print(sheets)
    for sheet in sheets:
        # 设置读取的sheet页面
        reader.set_sheet(sheet)
        writer.set_sheet(sheet)
        # 读取当前sheet的所有行
        lines = reader.readline()
        for i in range(len(lines)):
            line=lines[i]
            if len(line[0])>0 or len(line[1])>0:
                continue
            try:
                print("line的值：" + str(line))
                casename = line[2]
                key_word = line[3]
                params = line[4:]
                params = params[:params.index("")]
                print("params的值：" + str(params))
                func = getattr(webkeyword, key_word)
                res = func(*params)
                writer.write(i, 7, 'Pass',3)
                writer.write(i, 8, str(res))
            except Exception as e:
                writer.write(i, 7, 'Fail',2)
                writer.write(i, 8, str(traceback.format_exc()))
    writer.save_close()



if __name__ == '__main__':
    run_web()


